﻿Imports Microsoft.Win32

''' <summary>
''' Simpler String Zugriff auf CurrentUser-Zweig der Registry
''' </summary>
''' <remarks></remarks>
Public Class nativeRegistry

    ''' <summary>
    ''' Holt einen Wert aus der Registry
    ''' </summary>
    ''' <param name="key">Zweig</param>
    ''' <param name="name">Schlüsselname</param>
    ''' <returns>Wert</returns>
    ''' <remarks></remarks>
    Public Function getValue(ByVal key As String, ByVal name As String) As String
        Try
            Dim rkey As RegistryKey
            rkey = Registry.CurrentUser.OpenSubKey(key)
            Dim res As String = CStr(rkey.GetValue(name, ""))
            rkey.Close()

            Return res
        Catch ex As Exception
            Return ""
        End Try

    End Function

    ''' <summary>
    ''' Setzt einen Wert in CurrentUser
    ''' </summary>
    ''' <param name="key">Zweig</param>
    ''' <param name="name">Schlüsselname</param>
    ''' <param name="value">Wert</param>
    ''' <returns>Gibt True zurück, wenn erfolgreich</returns>
    ''' <remarks></remarks>
    Public Function setValue(ByVal key As String, ByVal name As String, ByVal value As String) As Boolean
        Dim rkey As RegistryKey

        Try
            rkey = Registry.CurrentUser.OpenSubKey(key, True)
            rkey.SetValue(name, value)

            rkey.Close()
            Return True
        Catch ex As Exception
            Return False
        End Try
    End Function

    ''' <summary>
    ''' Löscht einen Wert aus dem CurrentUser-Zweig
    ''' </summary>
    ''' <param name="key">Zweig</param>
    ''' <param name="name">Schlüssel</param>
    ''' <returns>Gibt True zurück, wenn erfolgreich gelöscht</returns>
    ''' <remarks></remarks>
    Public Function deleteValue(ByVal key As String, ByVal name As String) As Boolean
        Dim rkey As RegistryKey

        Try
            rkey = Registry.CurrentUser.OpenSubKey(key, True)
            rkey.DeleteValue(name)
            rkey.Close()
            Return True
        Catch ex As Exception
            Return False
        End Try
    End Function

End Class
